using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class ToolTip : MonoBehaviour
{
    [SerializeField] private TextMeshProUGUI ToolTiptext;
    [SerializeField] private Button[] buttons;
    // 切换设置面板
    [SerializeField] private SetSelect setSelect;
    // 基础设置
    [SerializeField] private JichuSet jichuSet;
    // 账目设置
    [SerializeField] private ZhangmuSet zhangmuSet;
    // 硬件测试
    [SerializeField] private YingjianSet yingjianSet;
    // 语言设置
    [SerializeField] private LanguageSet languageSet;
    // 确认按键文本
    [SerializeField] private TextMeshProUGUI confirm;
    // 取消按键文本
    [SerializeField] private TextMeshProUGUI cancel;

    private int index;
    string method;

    void Start()
    {
        buttons[index].Select();
    }

    void Update()
    {
        ToopTipSelect();

        // 判断执行什么函数
        if (Input.GetKeyDown(KeyCode.J) || ComTrans.Instance.GetsecSerial() || ComTrans.Instance.GetsetSerial())
        {
            if (index == 0)
            {
                switch (method)
                {
                    case "SaveAndEsc":
                        jichuSet.SaveAndEsc();
                        break;
                    case "DontSave":
                        jichuSet.DontSave();
                        break;
                    case "SaveAndDefault":
                        jichuSet.SaveAndDefault();
                        break;
                    case "ZhangmuCleanData":
                        zhangmuSet.ZhangmuCleanData();
                        break;
                    case "ZhangmuDontSave":
                        zhangmuSet.ZhangmuDontSave();
                        break;
                    case "YingjianDontSave":
                        yingjianSet.YingjianDontSave();
                        break;
                    case "LanguageSave":
                        languageSet.LanguageSave();
                        break;
                    case "LanguageDontSave":
                        languageSet.LanguageDontSave();
                        break;
                }
            }
            else if (index == 1)
            {
                index = 0;
                switch (method)
                {
                    case "SaveAndEsc":
                        jichuSet.set = false;
                        break;
                    case "DontSave":
                        jichuSet.set = false;
                        break;
                    case "SaveAndDefault":
                        jichuSet.set = false;
                        break;
                    case "ZhangmuCleanData":
                        zhangmuSet.set = false;
                        break;
                    case "ZhangmuDontSave":
                        zhangmuSet.set = false;
                        break;
                    case "YingjianDontSave":
                        yingjianSet.set = false;
                        break;
                    case "LanguageSave":
                        languageSet.set = false;
                        break;
                    case "LanguageDontSave":
                        languageSet.set = false;
                        break;
                }

            }
            gameObject.SetActive(false);
        }
    }

    // 小窗选择
    private void ToopTipSelect()
    {
        if (Input.GetKeyDown(KeyCode.Q) || ComTrans.Instance.GetHorizontalL() == -1)
        {
            if (--index < 0) index = buttons.Length - 1;
        }
        if (Input.GetKeyDown(KeyCode.E) || ComTrans.Instance.GetHorizontalR() == 1)
        {
            if (++index >= buttons.Length) index = 0;
        }
        buttons[index].Select();
    }

    // 设置文本内容
    public void SetupToolTipText(string _str, string _method)
    {
        if (setSelect.language == 0)
        {
            confirm.text = "确认";
            cancel.text = "取消";
        }
        else
        {
            confirm.text = "Confirm";
            cancel.text = "Cancel";
        }
        ToolTiptext.text = _str;
        method = _method;
    }
}
